package valueobject

import (
	"fmt"
	"strings"
)

var (
	GetAddressProvince = func(t Address) string { return t.Province }
	GetAddressDistrict = func(t Address) string { return t.District }
)

type Address struct {
	Province string `json:"province,optional"`
	City     string `json:"city,optional"`
	District string `json:"district,optional"`
	FullName string `json:"fullName,optional"`
}

func CodeAddress(addr Address) string {
	return fmt.Sprintf("%s-%s-%s", addr.Province, addr.City, addr.District)
}

func DecodeAddress(addr string) Address {
	address := Address{}
	addrArr := strings.Split(addr, "-")
	if len(addrArr) > 1 {
		address.Province = addrArr[0]
	}
	if len(addrArr) > 2 {
		address.City = addrArr[1]
	}
	if len(addrArr) > 3 {
		address.District = addrArr[2]
	}
	return address
}
